#include <stdio.h>
#include "log/log.h"
#include "cJSON/cJSON.h"

int main(int argc, char const *argv[])
{
    // 1.创建JSON对象
    char *name = "zhangsan";
    int age = 18;

    cJSON *json = cJSON_CreateObject();
    cJSON_AddStringToObject(json, "name", name);
    cJSON_AddNumberToObject(json, "age", age);

    char *jsonStr = cJSON_PrintUnformatted(json);

    log_info("JSON_Str:%s", jsonStr);

    // 2.解析JSON对象
    cJSON *json2 = cJSON_Parse(jsonStr);
    // cJSON *nameJson = cJSON_GetObjectItem(json2, "name");
    // char *name2 = cJSON_GetStringValue(nameJson);
    char *name2 = cJSON_GetObjectItem(json2, "name")->valuestring;
    int age2 = cJSON_GetObjectItem(json2, "age")->valueint;

    log_info("Name = %s,Age = %d", name2, age2);

    return 0;
}
